package com.ruoyi.mes.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mes.domain.MtrInfo;
import com.ruoyi.mes.service.IMtrInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 物料信息Controller
 *
 * @author LongAndHao
 * @date 2023-04-04
 */
@Api(tags = "物料信息")
@RestController
@RequestMapping("/mes/mtrinfo")
public class MtrInfoController extends BaseController {
    @Autowired
    private IMtrInfoService mtrInfoService;

    /**
     * 查询物料信息列表
     */
    @ApiOperation(value = "查询物料信息列表")
    @PreAuthorize("@ss.hasPermi('mes:mtrinfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(MtrInfo mtrInfo) {
        startPage();
        List<MtrInfo> list = mtrInfoService.selectMtrInfoList(mtrInfo);
        return getDataTable(list);
    }

    /**
     * 导出物料信息列表
     */
    @ApiOperation(value = "导出物料信息列表")
    @PreAuthorize("@ss.hasPermi('mes:mtrinfo:export')")
    @Log(title = "物料信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MtrInfo mtrInfo) {
        List<MtrInfo> list = mtrInfoService.selectMtrInfoList(mtrInfo);
        ExcelUtil<MtrInfo> util = new ExcelUtil<MtrInfo>(MtrInfo.class);
        util.exportExcel(response, list, "物料信息数据");
    }

    /**
     * 获取物料信息详细信息
     */
    @ApiOperation(value = "获取物料信息详细信息")
    @PreAuthorize("@ss.hasPermi('mes:mtrinfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(mtrInfoService.selectMtrInfoById(id));
    }

    /**
     * 新增物料信息
     */
    @ApiOperation(value = "新增物料信息")
    @PreAuthorize("@ss.hasPermi('mes:mtrinfo:add')")
    @Log(title = "物料信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MtrInfo mtrInfo) {
        return toAjax(mtrInfoService.insertMtrInfo(mtrInfo));
    }

    /**
     * 修改物料信息
     */
    @ApiOperation(value = "修改物料信息")
    @PreAuthorize("@ss.hasPermi('mes:mtrinfo:edit')")
    @Log(title = "物料信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MtrInfo mtrInfo) {
        return toAjax(mtrInfoService.updateMtrInfo(mtrInfo));
    }

    /**
     * 删除物料信息
     */
    @ApiOperation(value = "删除物料信息")
    @PreAuthorize("@ss.hasPermi('mes:mtrinfo:remove')")
    @Log(title = "物料信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(mtrInfoService.deleteMtrInfoByIds(ids));
    }
}
